﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Transactions;
using WXApi.Model;
using WxTenpay.Service.Model;
using WxTenpay.Service;

namespace WXApi.Controllers
{
    /// <summary>
    ///系统日志管理
    /// </summary>
    [Route("[controller]/[action]")]
    [ApiController]
    [Action]
    public class SysLogApiController : ReqDataControllerBase
    {
        private readonly ISysLog syslog;
        private readonly ISysLoginLog sysloginlog;
        public SysLogApiController(ISysLog _syslog, ISysLoginLog _sysloginlog)
        {
            syslog = _syslog;
            sysloginlog = _sysloginlog;
        }



        #region  系统错误日志
        /// <summary>
        /// 获取系统日志信息 
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpPost]
        public ActionResult GetLogList([FromBody] PageModel.PageParm parm)
        {
            try
            {
                var data = syslog.GetPages(parm);
                return Success(data);
            }
            catch (Exception ex)
            {
                ErrorLogDto model = new ErrorLogDto();
                model.data = "系统错误！";
                model._syslog = syslog;
                model.logmodel = new SysLogEntity { Action = "SysLogApi/GetLogList", Content = ex.ToString(), Name = "获取系统日志信息" };
                return ErrorLog(model);

            }
        }

        /// <summary>
        /// 获取系统日志详情
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpPost]
        public ActionResult GetModel(string gid)
        {
            try
            {
                var data = syslog.GetModel(x=>x.GuId== gid);
                return Success(data);
            }
            catch (Exception ex)
            {
                ErrorLogDto model = new ErrorLogDto();
                model.data = "系统错误！";
                model._syslog = syslog;
                model.logmodel = new SysLogEntity { Action = "SysLogApi/GetModel", Content = ex.ToString(), Name = "获取系统日志详情" };
                return ErrorLog(model);
            }
        }


        #endregion


        #region 系统操作信息 
        /// <summary>
        /// 获取系统操作信息 
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpPost]
        public ActionResult GetLoginLogList([FromBody] PageModel.PageParm parm)
        {
            try
            {
                var data = sysloginlog.GetPages(parm,x=>x.Id,02);
                return Success(data);
            }
            catch (Exception ex)
            {
                ErrorLogDto model = new ErrorLogDto();
                model.data = "系统错误！";
                model._syslog = syslog;
                model.logmodel = new SysLogEntity { Action = "SysLogApi/GetLoginLogList", Content = ex.ToString(), Name = "获取系统操作信息" };
                return ErrorLog(model);

            }
        }

        /// <summary>
        /// 获取系统操作信息详情
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpPost]
        public ActionResult GetLoginLogModel(string gid)
        {
            try
            {
                var data = sysloginlog.GetModel(x => x.GuId == gid);
                return Success(data);
            }
            catch (Exception ex)
            {
                ErrorLogDto model = new ErrorLogDto();
                model.data = "系统错误！";
                model._syslog = syslog;
                model.logmodel = new SysLogEntity { Action = "SysLogApi/GetLoginLogModel", Content = ex.ToString(), Name = "获取系统操作信息详情" };
                return ErrorLog(model);
            }
        }


        #endregion


    }
}
